package common.playerUpgrade.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import lz.controls.ImageContain;

	/**
	 *球员升级显示条目 
	 * @author lake
	 * 
	 */	
	public class PlayerUpgradeItem extends Sprite implements IComponent
	{
		private var symbolSkin		:MovieClip;//皮肤
		
		private var _data			:Object;
		private var imgCon			:ImageContain;
		
		public function PlayerUpgradeItem()
		{
			super();
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.res.PlayerUpgradeItem");
			this.addChild(symbolSkin);
			symbolSkin.txtUserName.text = "";
			symbolSkin.txtLevel.text	= "";
			for(var i :int = 1;i <= 6 ;i++)
			{
				symbolSkin["s" + i].gotoAndStop(1);
				symbolSkin["s" + i].txtValue.text = "";
			}
		}
		/**
		 * set data
		 * @param value
		 * 
		 */		
		public function set data(value :Object):void
		{
			
//			var addValue :int;
//			for(var i :int = 1;i <= 6 ;i++)
//			{
////				addValue = playerInfo.upBytFlag.readByte();
//				if(addValue)
//				{
//					symbolSkin["s" + i].gotoAndStop(2);
//					symbolSkin["s" + i].txtAddValue.text = "+" + addValue;
//					symbolSkin["s" + i].txtValue.text = (playerInfo["s" + i] - addValue) + "";
//				}
//				else
//				{
//					symbolSkin["s" + i].txtValue.text = playerInfo["s" + i] + "";
//				}
//			}
			reset();
			showAddValud(value.attachAdd,value.attach,1);
			showAddValud(value.speedAdd,value.speed,6);
			showAddValud(value.stealAdd,value.steal,5);
			showAddValud(value.defenceAdd,value.defence,4);
			showAddValud(value.powerAdd,value.power,3);
			showAddValud(value.controlAdd,value.control,2);
			
			
			var playerVo:PlayerVo = AppData.getInstance().playerCenterDataManager.getplayerVoById(value.playerid);
			if(playerVo == null)return;
			symbolSkin.txtUserName.text = playerVo.starVo.pname + "";
			symbolSkin.txtLevel.text	= playerVo.level + "";
			
			
			if(imgCon == null)
			{
				imgCon = new ImageContain();
				imgCon.setSize(50,50)
			}
			;
			imgCon.source = playerVo.starVo.bitmapData;
			symbolSkin.container.addChild(imgCon);
			symbolSkin.bg.gotoAndStop(playerVo.color);
		}
		
		
		private function showAddValud(addValue:int,valeu:int,i:int):void
		{
			if(addValue > 0)
			{
				symbolSkin["s" + i].gotoAndStop(2);
				symbolSkin["s" + i].txtAddValue.text = "+" + addValue;
				symbolSkin["s" + i].txtValue.text = valeu + "";
			}
			else
			{
				symbolSkin["s" + i].txtValue.text = valeu + "";
			}
		}
		private function reset():void
		{
			for(var i :int = 1;i <= 6 ;i++)
			{
				symbolSkin["s" + i].gotoAndStop(1);
				symbolSkin["s" + i].txtValue.text = "";
			}
		}
		
		/**
		 * get data
		 * @return 
		 * 
		 */		
		public function get data():Object
		{
			return _data;
		}
		/**
		 * 添加事件
		 * 
		 */		
		public function addEvtListener():void
		{
		}
		/**
		 * 
		 * 删除事件
		 */		
		public function removeEvtListener():void
		{
		}
		/**
		 * 销毁
		 * 
		 */		
		public function destroyView():void
		{
			removeEvtListener();
			DisplayObjectUtil.removeAllChildren(symbolSkin.container);
			_data = null;
			if(imgCon)
			{
				imgCon.clear();
				imgCon = null;
			}
		}
	}
}